package com.wbao.dianniu.ui;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.umeng.analytics.MobclickAgent;
import com.wbao.dianniu.R;
import com.wbao.dianniu.customView.NoDoubleClickListener;
import com.wbao.dianniu.listener.IFeedbackListener;
import com.wbao.dianniu.logical.GlobalContext;
import com.wbao.dianniu.manager.FeedbackManager;
import com.wbao.dianniu.utils.Notification;
import com.wbao.dianniu.utils.Utils;

/**
 * 问题反馈
 *
 * @author yejianjun
 */
public class FeedbackActivity extends BaseActivity implements IFeedbackListener {

    private EditText et_content;
    private EditText et_contact;
    private Button submitBtn;
    private FeedbackManager manager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentLayout(R.layout.activity_feedback);
        setTitleName("意见反馈");
        init();
        initManger();

    }

    private void init() {
        et_content = findViewById(R.id.feedback_content);
        et_contact = findViewById(R.id.feedback_contact);
        submitBtn = findViewById(R.id.feedback_submit);
        submitBtn.setOnClickListener(new NoDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
                if (TextUtils.isEmpty(et_content.getText().toString().trim())) {
                    Notification.toast(FeedbackActivity.this, "请输入您的宝贵意见");
                    return;
                }
                if (TextUtils.isEmpty(et_contact.getText().toString().trim())) {
                    Notification.toast(FeedbackActivity.this, "请输入联系方式");
                    return;
                }
                String version = Utils.getVersionName(FeedbackActivity.this);
                manager.feedback(GlobalContext.getAccountId(), et_content.getText().toString().trim(), et_contact.getText().toString().trim(), version, "a");
            }
        });
    }

    private void initManger() {
        manager = new FeedbackManager(this);
        manager.addFeedbackListener(this);
    }

    /*@Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.feedback_submit:
                if (TextUtils.isEmpty(et_content.getText().toString().trim())) {
                    Notification.toast(this, "请输入您的宝贵意见");
                    return;
                }
                if (TextUtils.isEmpty(et_contact.getText().toString().trim())) {
                    Notification.toast(this, "请输入联系方式");
                    return;
                }
                String version = Utils.getVersionName(this);
                manager.feedback(GlobalContext.getAccountId(), et_content.getText().toString().trim(), et_contact.getText().toString().trim(), version, "a");
                break;

            default:
                break;
        }
    }*/

    @Override
    public void onFeedbackFailure(int errorCode, String errorMsg) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onFeedbackSuccess() {
        // TODO Auto-generated method stub
        Notification.toast(this, "反馈成功");
        finish();
    }

    public void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    public void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (null != manager) {
            manager.removeFeedbackListener(this);
        }
    }
}
